package service;

import entity.Score;

import java.util.HashMap;
import java.util.Map;

//成绩管理类
public class ScoreManager {
    private final Map<String,Score> scores=new HashMap<>();
    public ScoreManager(){

    }

    public Map<String, Score> getScores() {
        return scores;
    }

    @Override
    public String toString() {
        return "service.ScoreManager{" +
                "scores=" + scores +
                '}';
    }

    //添加成绩
    public boolean addScore(Score score){
        if(scores.containsKey(score.getStudentId())){
            System.out.println("成绩已经存在，添加失败");
            return false;
        }
        scores.put(score.getStudentId(),score);
        System.out.println("成绩添加成功");
        return true;
    }
    //删除成绩
    public boolean deleteScore(String studentId){
        if(scores.containsKey(studentId)){
            scores.remove(studentId);
            System.out.println("成绩删除成功");
            return true;
        } else {
            System.out.println("学号不存在，成绩删除失败");
            return false;
        }
    }

    //更新成绩
    public boolean updateScore(Score updatescore){
        if(scores.containsKey(updatescore.getStudentId())){
            scores.put(updatescore.getStudentId(),updatescore);
            System.out.println("成绩更新成功");
            return true;
        }
        System.out.println("无此学号，成绩更新失败");
        return false;
    }

    //查询成绩
    public Score getScoreById(String studentId){
        if(scores.containsKey(studentId)){
            return scores.get(studentId);
        }
        System.out.println("学号不存在");
        return null;
    }

    //显示所有成绩
    public void  showScores(){
        if(scores.isEmpty()){
            System.out.println("无成绩");
            return;
        }
        for(Score score:scores.values()){
            System.out.println(score);
        }
    }
}